package com.qf.controller;

import com.qf.pojo.Sys_user;
import com.qf.pojo.Table;
import com.qf.service.UserService;
import org.aspectj.apache.bcel.generic.TABLESWITCH;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public Table userLogin(String tel, String password, HttpServletRequest request) {
        Sys_user user = userService.userLogin(tel, password);
        Table table = new Table();
        if (user != null) {
            request.getSession().setAttribute("user",user);
            table.setInfo(null);
            table.setCode(1);
            return table;
        }
        table.setInfo("用户名或密码错误");
        return table;
    }
}
